package com.sihai.controller;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeQueryRequest;
import com.sihai.utils.AlipayConfig;
/**
 * @ClassName Test
 * @Description: TODO
 * @Author wgc
 * @Date 2019/11/27 17:52
 * @Version V1.0
 **/
public class Test {
    //查询交易
    public static void main(String[] args) throws  Exception{
        //获得初始化的AlipayClient
        AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);

        //设置请求参数
        AlipayTradeQueryRequest alipayRequest = new AlipayTradeQueryRequest();

        //商户订单号，商户网站订单系统中唯一订单号
       String out_trade_no = new String("191127CM871650BC");
        //支付宝交易号
       String trade_no = new String("");
        //请二选一设置

         alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","+"\"trade_no\":\""+ trade_no +"\"}");

        //请求
        String result = alipayClient.execute(alipayRequest).getBody();
        System.out.println(result);
        net.sf.json.JSONObject  json = net.sf.json.JSONObject.fromObject(result);

        String trans=json.getString("alipay_trade_query_response");
        net.sf.json.JSONObject  result_ = net.sf.json.JSONObject.fromObject(trans);
        String code=result_.getString("code");



        System.out.println(code);
    }
}
